<template>
  <!--印章使用列表-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="印章编号">
              <a-input placeholder="请输入印章编号" v-model="queryParam.sealQualificationId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="印章名称">
              <a-input placeholder="请输入印章名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag placeholder="请选择单据来源" @input="handleDocumentSource" v-model="queryParam.permissionType"
                dictCode="permission_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="类别">
              <j-dict-select-tag placeholder="请选择印章类别" v-model="queryParam.sealType" dictCode="yzlx_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep :multi="false" v-model="queryParam.handlerId" placeholder="请选择申请人" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType != 3">
            <a-form-item label="申请人部门">
              <j-select-depart v-model="queryParam.handlerDeptId" placeholder="请选择申请人部门" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.bpmStatus" dictCode="bpm_status" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否盖章">
              <j-dict-select-tag placeholder="请选择是否盖章" v-model="queryParam.isStamped" dictCode="yes_no" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用印说明">
              <j-input placeholder="请选择用印说明" v-model="queryParam.userExplain" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus"
        :disabled="isDisabledAuth('erpSealCertificationUseRecord:add')">申请
      </a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('印章资质使用申请')"
                :disabled="isDisabledAuth('erpSealCertificationUseRecord:export')">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpSealCertificationUseRecord:import')">导入
        </a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpSealCertificationUseRecord:delete')">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle" />
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:'120%'}" :components="draggableComponent" bordered rowKey="id"
        :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps: getCheckboxProps}"
        class="j-table-force-nowrap" :customRow="customRow" @change="handleTableChange">
        <a slot="detail" :title="text" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)" type="notification" />
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.bpmStatus === '1' || (record.bpmStatus === '1'&&record.systemId === 'lims')">
            <a-button class="ruleButton" :ghost="true" type="primary" icon="edit" @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpSealCertificationUseRecord:edit')" />
            <template v-if="!(record.systemId === 'lims')">
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button class="ruleButton" :ghost="true" type="primary" icon="delete"
                  :disabled="isDisabledAuth('erpSealCertificationUseRecord:delete')" />
              </a-popconfirm>
            </template>
            <!-- <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="beginProcess(record)"
                      :disabled="isDisabledAuth('erpSealCertificationUseRecord:startProcess')">发起流程</a-button> -->
          </template>
          <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-divider type="vertical" />
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
          </template>
          <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-divider type="vertical" />
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical" />
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
              <a-button type="primary" size="small"
                :disabled="isDisabledAuth('erpSealCertificationUseRecord:invalidProcess')">
                作废流程
              </a-button>
            </a-popconfirm>
          </template>
          <template v-if="record.lendYn == 1 && record.checkStatus == 2 && record.returnSeal == '0'">
            <a-divider type="vertical"
              v-if="(record.bpmStatus === '1' || (record.bpmStatus === '1'&&record.systemId === 'lims')) || (showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1') || (queryParam.bizTaskType=='2' && showBtn(record.bpmStatus))" />
            <a-popconfirm title="是否确定归还?" @confirm="() => handleReturn(record)">
              <a-button type="primary" size="small"
                :disabled="isDisabledAuth('erpSealCertificationUseRecord:invalidProcess')">
                归还
              </a-button>
            </a-popconfirm>
          </template>
          <template v-if="record.bpmStatus !== '1'">
            <a-divider type="vertical"
              v-if="(record.bpmStatus === '1' || (record.bpmStatus === '1'&&record.systemId === 'lims')) || (showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1') || (queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)) || (record.lendYn == 1 && record.checkStatus == 2 && record.returnSeal == '0')" />
            <a-button type="primary" size="small" @click="handleTrack(record)"
              :disabled="isDisabledAuth('erpSealCertificationUseRecord:viewTrack')">审批进度</a-button>
          </template>
          <template v-if="record.isStamped === '0' && record.bpmStatus ==='3'">
            <a-divider type="vertical"
              v-if="(record.bpmStatus === '1' || (record.bpmStatus === '1'&&record.systemId === 'lims')) || (showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1') || (queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)) || (record.lendYn == 1 && record.checkStatus == 2 && record.returnSeal == '0') || (record.bpmStatus !== '1')" />
            <a-popconfirm title="是否确定盖章?" @confirm="() => handleStamp(record)">
              <a-button type="primary" size="small" :loading="record.stampLoading"
                :disabled="isDisabledAuth('erpSealCertificationUseRecord:invalidProcess')">
                盖章
              </a-button>
            </a-popconfirm>
          </template>
        </span>

      </a-table>
    </div>

    <erp-seal-certification-use-record-modal ref="modalForm"
      @ok="modalFormOk"></erp-seal-certification-use-record-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" isAfterStart="1" @ok="handleSuccess"
      @close="handleClose"></process-config-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpSealCertificationUseRecordModal from './modules/ErpSealCertificationUseRecordModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import { getAction } from '../../../../api/manage';
import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
export default {
  name: 'ErpSealCertificationUseRecordList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpSealCertificationUseRecordModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep,
    ProcessConfigModal
  },
  data() {
    return {
      description: '印章资质使用申请管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'applyCode',
          width: 200,
          scopedSlots: { customRender: 'detail' },
          ellipsis: true
        },
        // {
        //     title:'标题',
        //     align:"center",
        //     dataIndex: 'bpmBizTitle',
        //     ellipsis: true
        //   },
        {
          title: '印章资质所属公司',
          align: 'center',
          width: 200,
          dataIndex: 'sealCompany_dictText',
          ellipsis: true
        },
        {
          title: '用印说明',
          align: 'center',
          width: 200,
          dataIndex: 'userExplain',
          ellipsis: true
        },
        {
          title: '类别',
          align: 'center',
          width: 200,
          dataIndex: 'lb',
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          width: 200,
          dataIndex: 'handlerId_dictText',
          ellipsis: true
        },
        {
          title: '申请人部门',
          align: 'center',
          width: 200,
          dataIndex: 'handlerDeptId_dictText',
          ellipsis: true
        },
        {
          title: '归还状态',
          align: 'center',
          width: 200,
          dataIndex: 'returnSeal_dictText',
          ellipsis: true
        },
        {
          title: '是否盖章',
          align: 'center',
          width: 200,
          dataIndex: 'isStamped_dictText',
          ellipsis: true
        },
        {
          title: '状态',
          align: 'center',
          width: 200,
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          fixed: 'right',
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/administration/seal/erpSealUsageInformation/list',
        delete: '/api/erp/administration/seal/erpSealCertificationUseRecord/delete',
        deleteBatch: '/api/erp/administration/seal/erpSealCertificationUseRecord/deleteBatch',
        exportXlsUrl: '/api/erp/administration/seal/erpSealCertificationUseRecord/exportXls',
        importExcelUrl: 'administration/seal/erpSealCertificationUseRecord/importExcel',
        bizCount: '/api/erp/administration/seal/erpSealCertificationUseRecord/bizCount',
        updateReturnSeal: '/api/erp/administration/seal/erpSealCertificationUseRecord/updateReturnSeal',
        stamp: '/api/erp/administration/seal/erpSealUsageInformation/stamp'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_seal_usage_information_001',
      formUrl: '/erp/administration/seal/modules/ErpSealCertificationUseRecordForm',
      formUrlMobile: '/pages/synergy/certificationUseRecord',
      dictOptions: {},
      superFieldList: [],
      processId: '1559806248735576066',
      beanName: 'sealUseFlow'
    }
  },
  watch: {
    $route(to, from) {
      this.loadData();
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    beginProcess(record) {
      this.$refs.processConfig.visible = true
      this.$refs.processConfig.formUrl = this.formUrl
      this.$refs.processConfig.formUrlMobile = this.formUrlMobile
      this.$refs.processConfig.flowCode = this.flowCode
      this.$refs.processConfig.edit(record, this.processId, this.beanName)
    },
    handleSuccess() {
      this.loadData();
      this.onClearSelected();
      this.$refs.modalForm.handleCancel()
    },

    // 新增流程取消关闭弹窗刷新页面
    handleClose () {
      this.$refs.modalForm.handleCancel()
      this.loadData();
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'sealQualificationId', text: '印章编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '印章名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealType', text: '类别', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerId', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '申请人部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: 'bpm_status' })
      this.superFieldList = fieldList
    },
    handleReturn(record) {
      const params = {
        id: record.id,
        returnSeal: '1'
      }
      getAction(this.url.updateReturnSeal, params).then(res => {
        if (res.success) {
          this.loadData(1)
        }
      })
    },
    // 查看详情
      getDetail(id) {
        this.$router.push({
          path: `/erp/administration/seal/ErpSealCertificationUseRecordListDetail/${id}`
        })
      },
    // 流程审批结束禁用
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.bpmStatus !== '1' || record.systemId == 'lims'
        }
      }
    },
    // 盖章
    handleStamp(record) {
      this.$set(record, 'stampLoading', true)
      getAction(this.url.stamp, { id: record.id }).then(res => {
        if (res.success) {
          this.$message.success('操作成功!')
          this.loadData();
        } else {
          this.$message.warning('操作失败，请稍后重试!')
        }
      }).catch(e => {
        this.$message.warning('操作失败，请稍后重试!')
        console.log('盖章请求失败：', e)
      }).finally(() => {
        this.$set(record, 'stampLoading', false)
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
